package com.eshop.config;

import org.springframework.data.redis.serializer.SerializationException;
import com.eshop.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import cn.hutool.core.lang.Assert;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import org.springframework.data.redis.serializer.RedisSerializer;

class StringRedisSerializer implements RedisSerializer<Object>
{
    private final Charset charset;
    
    StringRedisSerializer() {
        this(StandardCharsets.UTF_8);
    }
    
    private StringRedisSerializer(final Charset charset) {
        Assert.notNull((Object)charset, "Charset must not be null!", new Object[0]);
        this.charset = charset;
    }
    
    public String deserialize(final byte[] bytes) {
        return (bytes == null) ? null : new String(bytes, this.charset);
    }
    
    public byte[] serialize(final Object object) {
        String string = JSON.toJSONString(object);
        if (StringUtils.isBlank((CharSequence)string)) {
            return null;
        }
        string = string.replace("\"", "");
        return string.getBytes(this.charset);
    }
}
